﻿@model PhoneStoreWeb.Models.ShoppingCartViewModel

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section LeftMenu
{
    <ul>
        @Html.Action(actionName: "CategoryMenu", controllerName: "Product")
    </ul>
}

@section RightMenu
{
    <div class="register">
        <img src="~/Images/Icons/ProductFeatures.png" alt="ProductFeatures.png" width="40" height="30" />
        <p>Giỏ hàng</p>
    </div>
}

<div id="update-message"></div>
<div class="shopping-cart">
@{
    using (@Html.BeginForm())
    {
        <table border="1">
            <tr>
                <th>Xóa</th>
                <th>STT</th>
                <th>Tên hàng</th>
                <th>Số lượng</th>
                <th>Đơn giá</th>
                <th>Thành tiền</th>
            </tr>
            @{
                int number = 0;
                decimal price = 0;
                foreach (var item in Model.CartItems)
                {
                    <tr id="row-@item.RecordID">
                        <td class="center">
                            @Html.ActionLink("Xóa", "RemoveFromCart", new { id = item.RecordID }, new { @class = "delete" })
                        </td>
                        <td class="center">
                            @{
                                ++number;
                            }
                            @number
                        </td>
                        <td>
                            @item.Product.Name
                        </td>
                        <td class="center">
                            @Html.TextBoxFor(m => m.CartItems[number - 1].Quantity)
                        </td>
                        <td class="center">
                            @if (!item.Product.IsPromotional)
                            {
                                price = item.Product.RetailPrice;
                            }
                            else
                            {
                                price = (int)item.Product.RetailPrice * (100 - (int)item.Product.Promotions.Last(p => p.ProductID == item.ProductID).Percentage) / 100;
                            }
                            <span>@String.Format("{0:C0}", price)</span>
                        </td>
                        <td class="right">
                            @{
                                decimal totalPrice = price * @item.Quantity;
                            }
                            <span>@String.Format("{0:C0}", totalPrice)</span>
                        </td>
                    </tr>
                }
                <tr>
                    <td colspan="5" class="right">
                        <b>Tổng cộng:</b>
                    </td>
                    <td class="right">
                        @String.Format("{0:C0}", Model.CartTotal)
                    </td>
                </tr>
            }
        </table>
        <br />
        @Html.ActionLink("Đặt hàng", "Index", "Checkout", null, new { @class = "buttons" })
        <input type="submit" value="Cập nhật" class="buttons"/>
        @Html.ActionLink("Tiếp tục mua", "Index", "Product", null, new { @class = "buttons" })
        @Html.ActionLink("Xóa giỏ hàng", "EmptyCart", "ShoppingCart", null, new { @class = "buttons" })
        <br />
    }
}
</div>